package com.huqu.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;


@SuppressWarnings("serial")
@ManagedBean(name = "demo")
@ViewScoped
public class demo implements Serializable {
	private String user;
	private String pass;
	private String message="";
	private List<String> listname=new ArrayList<String>();
	private UIData table;

	@PostConstruct
	public void init() {
		System.out.println("vao bean demo");
		listname.add("Quynh");
		listname.add("Thong");
		listname.add("Duy");
		listname.add("Thoai");
		listname.add("Dan");
		
	}

	public void login() {
		System.out.println("Bean login()");
		try {
			if (user.equals("quynhnc") && pass.equals("123456")) {
				System.out.println("login success.");
				message="Login success.";
				/*FacesContext.getCurrentInstance().addMessage(
						null,
						new FacesMessage(FacesMessage.SEVERITY_INFO, "Info: ",
								"Đăng nhập thành công."));*/
			} else {
				message="Login fail.";
				/*FacesContext.getCurrentInstance().addMessage(
						null,
						new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error: ",
								"Đăng nhập thất bại."));
				System.out.println("login fail.");*/
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<String> getListname() {
		return listname;
	}

	public void setListname(List<String> listname) {
		this.listname = listname;
	}

	public UIData getTable() {
		return table;
	}

	public void setTable(UIData table) {
		this.table = table;
	}
	

}
